// packageI/anytime_service/my/skill_order/skill_order.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    actions_name: "订单号",
    placeholder: "",
    active_name: 1,
    evaluation_show: false,
    tips: false,
    tips_type: 1,
    order_type: 1, //1-技能师傅接单、2-区域技能师傅订单
    keyword:"",
    page:1,
    total_page:1,
    list:[],
    point:{},
    urlStr:"",
    order_id:'',
    activeName:"all"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      order_type: options.order_type || '',//1-技能师傅订单、2-区域技能师傅订单
    });
    if (options.order_type == 1) {
      wx.setNavigationBarTitle({
        title: '技能师傅订单',
      })
    } else {
      wx.setNavigationBarTitle({
        title: '技能师傅订单',
      })
    }
    let address_point = wx.getStorageSync('address-point') || wx.getStorageSync('applyaddresspoint');
    if(address_point){
      this.setData({
        point:address_point.point
      })
      this.getData();
    }
  },
  search_handle(){
    this.getData()
  },
  commentEvent(){
    this.getData();
  },
  search_input(e){
    console.log(e);
    this.setData({keyword:e.detail});
  },
  tab_handle(e){
    this.setData({activeName:e.detail.name});
    this.getData();
  },
  goToAdress(e){
    let {latitude,longitude,full_address} =  e.currentTarget.dataset.item;
    let point = app.BMapTransqqMap(parseFloat(longitude),parseFloat(latitude));
    wx.openLocation({
      latitude: point.lat,
      longitude:  point.lng,
      scale: 18,
      name: full_address
    });
  },
  getData(page=1){
    let json = { page ,lng:this.data.point.lng,lat:this.data.point.lat};
    if(this.data.keyword){
      if(this.data.tips_type == 1){
        json.order_sn = this.data.keyword;
      } else {
        json.shifu_name =this.data.keyword;
      }
    }
    if (this.data.activeName !== 'all') {
      json.tab = this.data.activeName;
    }
    let urlStr = "plugin.be-within-call.frontend.order.shi-fu.index";
    if(this.data.order_type == '2'){
      urlStr = 'plugin.be-within-call.frontend.area-manage.order';
    }
    app._getNetWork({
      url:app.getNetAddresss(urlStr),
      data:json,
      success:resdata=>{
        let {result,msg,data} = resdata.data;
        if(result){
          if(page == 1){
            this.setData({list:data.data})
          }else{
            let list = this.data.list.concat(data.data);
            this.setData({list})
          }
          this.data.page = data.current_page;
          this.data.total_page = data.last_page;
        }else{
          app.tips(msg);
        }
      }
    })
  },
  choose(e) {
    if (e.currentTarget.dataset.i == 2) {
      let tips_type = this.data.tips_type == 1 ? 2 : 1;
      this.setData({
        tips_type,
        tips:false
      })
    } else {
      this.setData({
        tips: true
      })

    }
  },
  goOrderDetail(e) {
    let item = e.currentTarget.dataset.item;
    let name = this.data.order_type == 2 ? 'area' :'individual';
    let order_type = "";
    if (item.status == 3) {
      if(item.button_models && item.button_models.length!==0){
        order_type = 1;
      }else{
        order_type = 5
      }
    } else if (item.status == 2) {
      order_type = 2;
    } else if(item.status == 0){
      order_type = 4
    }
    wx.navigateTo({
      url: '/packageJ/anytime_service/my/order_detail/order_detail?order_type='+order_type+'&name='+name+'&order_id='+item.order_id,
    })
  },
  order_handle(e){
    let  item = e.currentTarget.dataset.item,
    order_id = e.currentTarget.dataset.id;
    if(item.value == 'shifu'){
      this.setData({
        urlStr:item.api,
        order_id,
        evaluation_show:true
      })
    }
    if (item.value == 'receive') {
      app._postNetWork({
        url:app.getNetAddresss("plugin.be-within-call.frontend.need-order-operate.receive"),
        data:{
          oid:order_id
        },
        success:resdata=>{
          let {result,msg} = resdata.data;
          app.tips(msg);
          if(result){
            this.getData()
          }
        }
      })
     
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.page >= this.data.total_page) {
      return;
    }
    let page = this.data.page + 1;
    this.getData(page);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})